Telegram Group & Telegram Channel
5. Lists

>>> list=[8,0,5,1]
>>> list
[8, 0, 5, 1]

>>> len(list)
4

>>> list_2=['string',8086,'p']
>>> list_2
['string', 8086, 'p']

>>> len(list_2)
3

Indexing and Slicing

>>> list=['one','ox','ok']
>>> list[0]
'one'

>>> list[1:]
['ox', 'ok']

>>> list[:2]
['one', 'ox']

>>> list[-1]
'ok'

>>> list[::-1]
['ok', 'ox', 'one']

>>> list+[235]
['one', 'ox', 'ok', 235]

>>> list*2
['one', 'ox', 'ok', 'one', 'ox', 'ok']

Basic List Methods

>>> list=[4,0,1,3]
>>> list.append("new")
>>> list
[4, 0, 1, 3, 'new']

>>> list.pop(0)
4
>>> list
[0, 1, 3, 'new']

>>> list.reverse()
>>> list
['new', 3, 1, 0]


Nesting Lists

>>> lst_1=[1,2,3]
>>> lst_2=[4,5,6]
>>> lst_3=[7,8,9]
>>> matrix = [lst_1,lst_2,lst_3]
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

>>> matrix[1]
[4, 5, 6]

>>> matrix[0][1]
2

@python_codes



tg-me.com/python_codes/8
Create:
Last Update:

5. Lists

>>> list=[8,0,5,1]
>>> list
[8, 0, 5, 1]

>>> len(list)
4

>>> list_2=['string',8086,'p']
>>> list_2
['string', 8086, 'p']

>>> len(list_2)
3

Indexing and Slicing

>>> list=['one','ox','ok']
>>> list[0]
'one'

>>> list[1:]
['ox', 'ok']

>>> list[:2]
['one', 'ox']

>>> list[-1]
'ok'

>>> list[::-1]
['ok', 'ox', 'one']

>>> list+[235]
['one', 'ox', 'ok', 235]

>>> list*2
['one', 'ox', 'ok', 'one', 'ox', 'ok']

Basic List Methods

>>> list=[4,0,1,3]
>>> list.append("new")
>>> list
[4, 0, 1, 3, 'new']

>>> list.pop(0)
4
>>> list
[0, 1, 3, 'new']

>>> list.reverse()
>>> list
['new', 3, 1, 0]


Nesting Lists

>>> lst_1=[1,2,3]
>>> lst_2=[4,5,6]
>>> lst_3=[7,8,9]
>>> matrix = [lst_1,lst_2,lst_3]
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

>>> matrix[1]
[4, 5, 6]

>>> matrix[0][1]
2

@python_codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/8

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Work?

Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”

Python Codes from kr


Telegram Python Codes
FROM USA